{layout name="layout/food" /}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">智能设备列表</div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom am-cf">
                        <form class="toolbar-form" action="{:url('food.shop.device/index')}">
                            <div class="am-u-sm-12 am-u-md-3">
                                <div class="am-form-group">
                                    <div class="am-btn-group am-btn-group-sm">
                                        <a class="am-btn am-btn-primary am-radius"
                                           href="{:url('food.shop.device/add')}">
                                            <span class="am-icon-plus"></span> 新增
                                        </a>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-9">
                                <div class="am fr">
                                    {if $user['applet']['shop_mode']['value']==20}
                                    <div class="am-form-group am-fl">
                                        <select name="shop_id"
                                                data-am-selected="{btnSize: 'sm', placeholder: '全部门店'}">
                                            <option value=""></option>
                                            {if isset($shoplist)}
                                                {foreach $shoplist as $item}
                                                <option value="{$item['shop_id']}" {$shop_id == $item['shop_id'] ? 'selected' : ''}>{$item['shop_name']}</option>
                                                {/foreach}
                                            {/if}
                                        </select>
                                    </div>
                                    {/if}
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <div class="am-input-group-btn">
                                                <button class="am-btn am-btn-default am-icon-search" type="submit"></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-hover tpl-table-black">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>门店</th>
                                <th>设备</th>
                                <th>名称</th>
								<th>设备ID</th>
								<th>设备KEY</th>
								<th>联网</th>
                                <th>状态</th>
                                <th>时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {if sizeof($list) > 0}
                                {foreach $list as $item}
                                <tr>
									<td class="am-text-middle">
                                        <p class="item-title">{$item['device_id']}</p>
                                    </td>
									<td class="am-text-middle">{$item['shop']['shop_name']}</td>
                                    <td class="am-text-middle">{$item['dev_type']['text']}</td>
                                    <td class="am-text-middle">{$item['dev_name']}</td>
                                    <td class="am-text-middle">{$item['dev_id']}</td>
									<td class="am-text-middle">{$item['dev_key']}</td>
									<td class="am-text-middle">
                                            <span class="<?= $item['status'] == '正常' ? 'x-color-green' : 'x-color-red'?>">
                                            {$item['status']}
                                            </span>
                                    </td>
                                    <td class="am-text-middle">
                                        <span class="j-open am-badge x-cur-p {$item['is_open']['value'] == 1 ? ' am-badge-success' : ' am-badge-warning'}" 
                                             data-id="{$item['device_id']}"
                                             data-status="{$item['is_open']['value']}">
                                            {$item['is_open']['text']}
                                        </span>
                                    </td>
                                    <td class="am-text-middle">{$item['create_time']}</td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="{:url('food.shop.device/edit',['id' => $item['device_id']])}">
                                                <i class="am-icon-pencil"></i> 编辑
                                            </a>
                                            <a href="javascript:;" class="hema-del tpl-table-black-operation-del"
                                               data-id="{$item['device_id']}">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {/foreach}
                            {else /}
                                <tr>
                                    <td colspan="10" class="am-text-center">暂无记录</td>
                                </tr>
                            {/if}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {

        // 切换开关状态
        $('.j-open').click(function () {
            var data = $(this).data();
            var msg = '确定要'+(parseInt(data.status) === 1 ? '关闭' : '开启')+'该设备？';
            var url = "{:url('food.shop.device/status')}";
            $('.j-open').del('id', url,msg);
        });

        // 删除元素
        var url = "{:url('food.shop.device/delete')}";
        $('.hema-del').del('id', url);

    });
</script>

